<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\user;

use think\Model;

/**
 * 用户反馈 模型
 * @package app\user_center\model
 */
class UcMemberFeedback extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_feedback';

    public static function init()
    {
        
        
    }

    /**
     * 添加数据
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function addData($uid, $content){
        $data['uid']                    = $uid;
        $data['content']                = $content;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
    
	/**
     * 获取用户统计信息
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getDataByUid($uid){
        $map = [];
        $map['uid'] = $uid;
        $info = self::where($map)->find();
        if(empty($info)){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 粉丝数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incFansTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('fans_times', $times);

        //更新热度
        $map = [];
        $map['uid'] = $uid;
        $rel = $this -> where($map) -> find();
        $num = $rel->fans_times*5 + $rel->be_praised_times*1;
        $this -> updateHotNum($uid, $num);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 粉丝数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decFansTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('fans_times', $times);

        //更新热度
        $map = [];
        $map['uid'] = $uid;
        $rel = $this -> where($map) -> find();
        $num = $rel->fans_times*5 + $rel->be_praised_times*1;
        $this -> updateHotNum($uid, $num);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 关注数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incFollowTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('follow_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 关注数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function decFollowTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('follow_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 登录数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incLoginTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('login_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 登录数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decLoginTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('login_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 好友数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incFriendTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('friend_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 好友数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decFriendTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('friend_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 作品数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incWorkTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('works_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 作品数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decWorkTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('works_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 获赞数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incBePraisedTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('be_praised_times', $times);

        //更新热度
        $map = [];
        $map['uid'] = $uid;
        $rel = $this -> where($map) -> find();
        $num = $rel->fans_times*5 + $rel->be_praised_times*1;
        $this -> updateHotNum($uid, $num);

        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 获赞数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decBePraisedTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('be_praised_times', $times);

        //更新热度
        $map = [];
        $map['uid'] = $uid;
        $rel = $this -> where($map) -> find();
        $num = $rel->fans_times*5 + $rel->be_praised_times*1;
        $this -> updateHotNum($uid, $num);

        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

	/**
     * 点赞数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incPraisedTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('praised_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
    
	/**
     * 点赞数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decPraisedTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('praised_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 评论数增加
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incCommentTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('comment_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

	/**
     * 评论数减少
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function decCommentTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setDec('comment_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 权限密钥获取次数
     * @param int $uid 用户id
     * @param int $times 数量（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
    public function IncAccesstokenTodayTimes($uid, $times = 1){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map) -> setInc('access_token_today_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 更新用户热度
     * @param int $uid 用户id
     * @param int $num 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    private function updateHotNum($uid, $num=0){
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> where($map)->setField('hot_num', $num);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 用户信息 关联载入（一对一）
     */
    public function getMember(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'uid');
    }
}
